﻿using System;
using System.Linq;
using System.Windows.Media.Imaging;


namespace BeerManagementSystem
{
    public partial class BeerdocterProfile
    {
        public string beerdocterImagePath;
       public Beerdocter _beerdocter;


        public BeerdocterProfile(Beerdocter beerdocter)
        {
            _beerdocter = beerdocter;
            BitmapImage = new BitmapImage();
        }

        public Beerdocter Beerdocter
        {
            get { return _beerdocter; }
        }

        public BitmapImage BitmapImage { get; set; }

        public Beerdocter calcBeerdocter()
        {
            DateTime reportStart;
            DateTime reportEnd;

            reportEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0);
            reportStart = reportEnd.AddMonths(-1);

            LinqToBeerDataContext data = new LinqToBeerDataContext();
            
            Beerdocter bdnew = new Beerdocter();
            try
            {
                var bd =
                from u in data.User
                join t in data.Transaction
                on u.ID equals t.UserID
                where (t.Timestamp.CompareTo(reportStart) > 0) && (t.Timestamp.CompareTo(reportEnd) < 0)
                select u;
                User user = bd.First();
                ////log.WriteMessage(user.ID + user.FirstName);
                
                
                

            }
            catch (Exception e)
            {
                
                ////log.WriteMessage("Beerdocter: Calculate Current Docter " + e.StackTrace);

            }
            return bdnew;
        }
    //    var query =
    //from order in orders.AsEnumerable()
    //join detail in details.AsEnumerable()
    //on order.Field<int>("SalesOrderID") equals
    //    detail.Field<int>("SalesOrderID")
    //where order.Field<bool>("OnlineOrderFlag") == true
    //&& order.Field<DateTime>("OrderDate").Month == 8
    //select new
    }
    //    // Bph ins die Datenbank schreiben
    //                var user = from us in data.User
    //                           where us.ID == lastTransactionUserResult.First().ID
    //                           select us;
    //                //log.WriteMessage("Last User: " + user.First().ID);
    //                if ((bph > 0) && (bph < 10) && (lastTransactionUserResult.First().Bph < bph)) user.First().Bph = bph;  // Schreibt den BPH-Wert in die Datenbank, wenn er zwischen 0 und 10 liegt
    //                //log.WriteMessage("Bph:       " + lastTransactionUserResult.First().Bph);
    ////                data.SubmitChanges();
    //User user = userResult.First();

    //                Transaction ta = new Transaction();
    //                ta.User = user;
    //                ta.Timestamp = DateTime.Now;
    //                ta.Type = type;
              
    //                data.Transaction.InsertOnSubmit(ta);
    //                data.SubmitChanges();
}
